//
//  EnumerationStudy.swift
//  Swift3.0_Study
//
//  Created by chengfeng on 2016/9/27.
//  Copyright © 2016年 zhaochengfeng. All rights reserved.
//

import Cocoa

enum Weather: Int {
    case sunny = 0
    case cloudy
    case rainy
    case snow
    case froggy
    
    func getOriginValue(weather: Weather) -> Int {
        return weather.rawValue
    }
}

enum Rank: Int {
    case ace = 1
    case two, three, four, five, six, seven, eight, nine, ten
    case jack, queen, king
}

//附加值(选修): 每一种类型都可附加一个或多个值，形式是元组。 🌰case 类型(Int,String,...)
enum WeatherDetail {
    case sunny(wendu: Int, kejiandu: Int, desc: String)
    case froggy(String, Int)
}

class EnumerationStudy: NSObject {
    func start() -> Void {
        /*
         计数、列举（有限的情况）；详细叙述之意。“增强的、更抽象型“的数字类型。
         非常强大，与switch语句结合使用，天生一对。
 
        
        定义和使用 ：
        
        给定一个名称, 然后把每一种情况列举出来.
         */
        

        //使用：点语法
        print(Weather.sunny)
        let todayweather = getWeather()
        print("\(todayweather) 的原始值是 \(todayweather.getOriginValue(weather: todayweather))")
        switch todayweather {
        case .cloudy:
            print("今天天气多云")
        case .sunny:
            print("天气晴朗")
        default:
            print("天气状况未知")
        }
        
        let today = getWeatherDetail()
        print(today)
        
        switch today {
        case .sunny(wendu: let x, kejiandu:let y, desc:let z):
            print("x = \(x), y = \(y), z = \(z)")
        case .froggy(let x, let y):
            print("x = \(x), y = \(y)")
//        default:
//            print("未识别")
        }
        
        enum ErrCode: Int {
            case err1, err2, err3
            mutating func change(err: ErrCode, newValue: ErrCode) -> Void {
                self = newValue
                
//                print(err)
            }
        }
        
        var err = ErrCode.err1;
        err.change(err: err, newValue: ErrCode.err2)
        print(err);
        
        
        let card1 = Rank.queen
        let card2 = Rank.king
        
        print(self.compareCard(a: card1, b: card2))
    }
    
    func compareCard(a: Rank, b: Rank) -> Bool {
        return a.rawValue > b.rawValue
    }
    
    func getWeather() -> Weather {
        return Weather.froggy
    }
    
    func getWeatherDetail() -> WeatherDetail {
        return WeatherDetail.sunny(wendu: 25, kejiandu: 10000, desc: "蓝天")
    }
    
}
